#include<vector>
using namespace std;
class Solution {
public:
    bool isIdealPermutation(vector<int>& A) {
        int min_=INT32_MAX;
        for (int i = A.size() - 1; i >= 2; --i) {
            if (min_ > A[i])min_ = A[i];
            if (min_ < A[i - 2])return false;
        }
        return true;
    }
};